﻿@{
    ViewBag.Title = "用户管理";
}
@using FMS.UI.Extension;
@section headSecion{
    <script type="text/javascript">
        var roleNames = "";
        $(function () {
            //获取所有用户的角色
            roleUserName();
            $.globalHelper.datagridPara.init("/Admin/Employee/EmpIndex", [@Html.GetSonBtnJs()], [
                [
                    { field: 'empLoginName', title: '工号', width: 60 },
                    { field: 'empCnName', title: '姓名', width: 60 },
                    {
                        field: 'Department',
                        title: '部门',
                        width: 60,
                        formatter: function (colData) {
                            return colData.depName;
                        }
                    },
                    {
                        field: 'empId',
                        title: '用户角色',
                        width: 60,
                        formatter: function (empId) {
                            return roleNameByUser(empId);
                        }
                    },
                     {
                         field: 'empIsDel',
                         title: '是否控制查看',
                         width: 60,
                         formatter: function (empIsDel) {
                             switch (empIsDel)
                             {
                                 case true:                             
                                     return "是";
                                 case false:
                                     return "否";
                             }
                         }
                     },
                    { field: 'empCellPhone', title: '电话', width: 60 },
                    {
                        field: 'empAddTime',
                        title: '创建时间',
                        width: 100,
                        formatter: function (colData) {
                            return $.globalHelper.changeDateFormat(colData);
                        }
                    }
                ]
            ]);
            $("#tbList").datagrid($.globalHelper.datagridPara.paras);
            $("#dlg").dialog({
                title: '消息提示框',
                iconCls: "icon-edit",
                width: 300,
                height: 200,
                closed: true,
                modal: true,
                buttons: [
                    {
                        text: 'Ok',
                        iconCls: 'icon-ok',
                        handler: function () {
                            alert('ok');
                        }
                    }, {
                        text: 'Cancel',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $('#dlg').dialog('close');
                        }
                    }
                ]
            });
        });

        //自动生成添加按钮
        @if (Html.IsBtnExist("add"))
        {
            <text>
        function add() {
            $.globalHelper.showCommonWindow("新增员工", "/admin/Employee/EmpADD", 375, 275);
        }
        </text>
        }
        @if (Html.IsBtnExist("viewSons"))
                {
                    <text>
        function viewSons() {         
            ifSelected(function (selectedRowData) {
                $.globalHelper.showCommonWindow("修改密码", "/admin/Employee/EmpPwd/"+ selectedRowData.empId, 310, 180);
            });
        }
        
        </text>
                }
        @if (Html.IsBtnExist("remove"))
        {
            <text>
        function remove() {

            ifSelected(function (selectedRowData) {
                window.top.ComSkipMsg(selectedRowData, "/Admin/Employee/EmpDel");
            });
        }

        </text>
        }

        @if (Html.IsBtnExist("modify"))
        {
            <text>
        function modify() {

            ifSelected(function (selectedRowData) {
                $.globalHelper.showCommonWindow("修改员工", "/admin/Employee/EmpModify/" + selectedRowData.empId, 320, 210);
            });
        }
        </text>

        }

        @if (Html.IsBtnExist("setUserRole"))
        {
            <text>
        function setUserRole() {

            ifSelected(function (selectedRowData) {
                $.globalHelper.showCommonWindow("分配角色", "/admin/Employee/UserRName/" + selectedRowData.empId, 315, 290);
            });
        }
        </text>

        }

        //统一判断是否有选中行 有则调用回掉函数(func) 并存入选中行的数据
        function ifSelected(func) //func回调函数 去执行操作
        {
            //获取选中行数据
            var selectedRowData = $("#tbList").datagrid("getSelected");
            if (selectedRowData) {
                if (func && func instanceof Function) {
                    $.ajax({
                        url: "/Admin/Employee/EmpCheck",
                        type: "post",
                        data: { ss: selectedRowData.empId },
                        success: function (da) {
                            if (da == 1) {
                                $.msgBoxObj.showInfo("用户名不存在");
                                $.globalHelper.reloadSeletecTabDataGrid();
                            } else {
                                func(selectedRowData); //调用回调函数，并传入 选中行的数据
                            }
                        },
                        async: true
                    });
                }
            } else {
                $.msgBoxObj.showInfo("请选中要操作的行");
            }


        }
        //获取所有用户的角色
        function roleUserName() {
            $.ajax({
                url: "/Admin/Employee/RoleName",
                type: "post",
                data: {},
                success: function (data) {
                    roleNames = data;
                },
                async: true
            });
        }
        //根据用户id获取角色名称
        function roleNameByUser(id) {
            var rname;
            $.each(JSON.parse(roleNames), function (index, names) {
                if (id == names.id) {

                    rname = names.Name.toString();
                }
            });
            return rname;
        }
    </script>
}
<table id="tbList" style="width:100%"></table>



